50
Beginner’s Guide to Code Algorithms
50
STEP 11 continued
Once identified, we store the two digits as a string in an array we call
putnumberpresent.
If sbox(i, j) = ““ And cantbelistcount(i, j) = 7 Then
putnumberpresent(i, j) = ““
For putnumber = 1 To 9
If findincantbelist(putnumber, i, j) = 0 Then
putnumberpresent(i, j) = putnumberpresent(i, j) & putnumber
End If
Next putnumber
End If
Now we check the entire row and add the pair to the cantbelist for those cells. As
you see below, it is done in three parts—first part being from the first member of the
row to the cell before the first member of the pair (1 to k-1), the second from the cell
straight after the first member of the pair to the one just before the second member
of the pair (k+1 to i-1), the third from the cell just after the second member of the
pair to the last cell of the row (i+1 to 9).
For k = 1 To i - 1
If putnumberpresent(k, j) <> ““ And
putnumberpresent(k, j) = putnumberpresent(i, j) Then
For kk = 1 To k - 1
Call addtocantbelist(Mid(putnumberpresent(k, j), 1, 1), kk, j)
Call addtocantbelist(Mid(putnumberpresent(k, j), 2, 1), kk, j)
Next kk
For kk = k + 1 To i - 1
Call addtocantbelist(Mid(putnumberpresent(k, j), 1, 1), kk, j)
Call addtocantbelist(Mid(putnumberpresent(k, j), 2, 1), kk, j)
Next kk
For kk = i + 1 To 9
Call addtocantbelist(Mid(putnumberpresent(k, j), 1, 1), kk, j)
Call addtocantbelist(Mid(putnumberpresent(k, j), 2, 1), kk, j)
Next kk
Exit For
End If
Next k
Next j
Next i
STEP 12
The next step is to do the same for each column.
For i = 1 To 9
For j = 1 To 9
cantbelistcount(j, i) = 0
For k = 1 To 9
If cantbelist(j, i, k) <> 0 Then
cantbelistcount(j, i) = cantbelistcount(j, i) + 1
End If